import React from 'react'
import Layout from '@/components/layout'
import PostsGroupByYear from '@/components/posts-group-by-year'
import { getAllPosts } from '@/lib/apis'
import PostType from '@/types/post'

import type { GetStaticProps, NextPage } from 'next'
export type PostsProps = {
  allPosts: PostType[]
}

export const getStaticProps: GetStaticProps = async () => {
  const allPosts = getAllPosts()
  return {
    props: {
      allPosts,
    },
    revalidate: 1,
  }
}

const Posts: NextPage<PostsProps> = ({ allPosts }) => {
  return (
    <Layout>
      <PostsGroupByYear posts={allPosts} />
    </Layout>
  )
}

export default Posts
